﻿using Microsoft.Extensions.DependencyInjection;
using Stee.CAP8.MessageBus.Sagas.Core.Extensions;
using Stee.CAP8.MessageBus.Sagas.Messages.Events.Orders;
using Stee.CAP8.MessageBus.Sagas.Messages.Events.Payment;
using Stee.CAP8.MessageBus.Sagas.Order.Handlers;
using Stee.CAP8.MessageBus.Sagas.Order.Sagas;
using Stee.CAP8.MessageBus.Sagas.Order.Services;
using System;

namespace Stee.CAP8.MessageBus.Sagas.Order
{
    class Program
    {
        static void Main(string[] args)
        {
            var services = new ServiceCollection();
            //services.UseKafkaSubsrcibeStore();
            //services.AddSaga<OrderSaga>();
            services.UseKafkaSubsrcibeStore().AddEventBus()
                .AddMessagebusHandler<OrderSaga>()
                //.AddMessagebusHandler<OrderHandler>()
                .UseEventBus(bus =>
            {
                bus.HandleEvent();


            });

            services.AddSubscrbe<OrderCreationEvent>();
            services.AddSubscrbe<PayemntedEvent>();
            services.AddSingleton(typeof(IOrderService), typeof(OrderService));
            var orderService = services.BuildServiceProvider().GetService<IOrderService>();
            while (true) 
            {
                Console.ReadLine(); 
                orderService.CreateOrder(new OrderInfo
                {
                    Id = Guid.NewGuid(),
                    Name = "测试买个东西"
                });

            }
            
        }
    }
}
